package com.zt.english.service

import android.app.Notification
import android.app.NotificationManager
import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.IBinder
import android.os.SystemClock
import com.zt.english.R

/**
 *  移除前台Service通知栏标志，这个Service选择性使用
 */
class CancelNoticeService :Service() {
    override fun onBind(intent: Intent?): IBinder? {
        return null
    }

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        // 开启一条线程，去移除DaemonService弹出的通知
        Thread(Runnable { // 延迟1s
            SystemClock.sleep(1000)
            // 取消CancelNoticeService的前台
            stopForeground(true)
            // 移除DaemonService弹出的通知
            val manager: NotificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
            manager.cancel(AudioService.NOTICE_ID)
            // 任务完成，终止自己
            stopSelf()
        }).start()
        return super.onStartCommand(intent, flags, startId)
    }
}